/*
* Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
*
* Oracle is a registered trademarks of Oracle Corporation and/or its affiliates.
*
* This software is the confidential and proprietary information of
* Oracle Corporation.  You shall not disclose such confidential and
* proprietary information and shall use it only in accordance with the
* terms of the license agreement you entered into with Oracle.
*
* This notice may not be removed or altered.
*/
using System;
using System.Windows.Forms;
using System.Threading;
using Tangosol.Net;
using Coherence.Patterns.Security;

namespace Examples
{
    static class ContactCacheClient
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Thread.CurrentPrincipal = new KerberosTokenPrincipal();

            INamedCache cache = CacheFactory.GetCache("dist-mde-genre-definitions");
            int size = cache.Count;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                ContactForm form = new ContactForm();
                Application.ApplicationExit += new EventHandler(ShutdownCoherenceClient);
                Application.Run(form);
            }
            catch (Exception)
            {
                MessageBox.Show("In order to run this sample application you need to make " +
                                "sure that the Coherence server is started and that the configuration " +
                                "parameters used to connect to it are correct.\n" +
                                "If the Coherence server is already running, check whether the " +
                                "server address and port number in the cache-config.xml are correct. " +
                                "Otherwise, start the Coherence server and retry.",
                                "Unable to connect to a Coherence server",
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }

        /// <summary>
        /// An event handler that gracefully shuts down Coherence client
        /// when application is terminated.
        /// </summary>
        private static void ShutdownCoherenceClient(object sender, EventArgs e)
        {
            CacheFactory.Shutdown();
        }

    }
}